#encoding=utf-8

import pymongo
import mongo_conn
import sys

reload(sys)
sys.setdefaultencoding('utf-8')
dbconn = mongo_conn.DBConn()

conn = None
quotes = None

def process():
    dbconn.connect()
    conn = dbconn.getConn()
    print conn.address
    quotes = conn.lifeba.quotes

    # datas ={"title":"天下无贼","authors":["刘德华","王宝强","葛优"],
    #          "quotes":["天下无贼算是一部理想电影，但是现实中却有很多无奈",
    #                    "天下无贼将人与人的新展示出来"],'id':1,
    #         "tags":["傻根","理想","偷盗","盗亦有道"]}
    # quotes.insert(datas)
    # print "新增成功》》"
    #
    # datas2 = [{"title": "三傻大闹宝莱坞", "authors": "印度人",
    #          "quotes": ["学习是什么？学习是一个不断进步的故事，而人必须倾尽他的热情",
    #                     "到底是天真还是坚持？","坚持人生之中的美好，坚持心灵的安慰"], 'id': 2,
    #          "tags": ["热爱学习", "喜剧", "戏剧", "学习","理想"]},
    #           {"title": "超人", "authors": "美国人",
    #            "quotes": ["超人背叛了自己的种族，但是却是拯救了人类，这算是什么？",
    #                       "人类在超自然的力量面前果然是无助和无能的",
    #                       "人类应该要掌控这个自然的力量"], 'id': 3,
    #            "tags": ["拯救", "爱情", "背叛", "超人"],
    #            },{"title": "超人2", "authors": "美国人",
    #            "quotes": ["超人背叛了自己的种族，但是却是拯救了人类，这算是什么？",
    #                       "人类在超自然的力量面前果然是无助和无能的",
    #                       "人类应该要掌控这个自然的力量"], 'id': 4,
    #            "tags": ["拯救", "爱情", "背叛", "超人2"]}
    #           ]
    # quotes.insert(datas2)

    quotes_find = quotes.find({"id":{"$gt":2}})
    for quote in quotes_find:
        for key in quote.keys():
            print quote[key]
        print "========================"


    dbconn.close()

if __name__ =="__main__":
    process()